package com.itgaoshu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itgaoshu.bean.Huishou;
import com.itgaoshu.bean.Jilu;
import com.itgaoshu.bean.Pharmacy;
import com.itgaoshu.service.JiLuservice;
import com.itgaoshu.service.PharmacyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * \* @author: 李豪杰
 * \* Date: 2021/3/19
 * \* Time: 15:51
 * \* Description:
 * \
 */
@Controller
@RequestMapping("pharmacy")
public class PharmacyController {
    @Autowired
    private PharmacyService pharmacyService;
    @Resource
    private JiLuservice jiLuservice;
    /**
     * 查询药品
     * @return
     */
    @RequestMapping("selectAllPharmacys")
    @ResponseBody
    public Object selectAllPharmacys(Pharmacy pharmacy, Integer page, Integer limit){
        PageHelper.startPage(page, limit);
        List<Pharmacy> list = pharmacyService.selectAllPharmacy(pharmacy);
        PageInfo pageInfo = new PageInfo(list);
        Map<String, Object> map = new HashMap<String, Object>();
        //用map集合绑定 layui要求的格式
        map.put("code", 0);
        map.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        map.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        map.put("data", pageInfo.getList());
        return map;

    }
    //查询药品仓库
    @RequestMapping("selecthuishou")
    @ResponseBody
    public Object selecthuishou(Huishou huishou, Integer page, Integer limit) {
        System.out.print("进去查询药房方法");
        PageHelper.startPage(page, limit);
        List<Huishou> drugstores = pharmacyService.selhuishou(huishou);
        PageInfo pageInfo = new PageInfo(drugstores);
        Map<String, Object> drugstoresData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        drugstoresData.put("code", 0);
        drugstoresData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        drugstoresData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        drugstoresData.put("data", pageInfo.getList());
        return drugstoresData;
    }
    @RequestMapping("delhuishou")
    @ResponseBody
    public  Integer delhuishou(Huishou huishou, Jilu jilu){
        //删除回收表此药（处理）
        System.out.println("进入处理");
        int delhuishou = pharmacyService.delhuishou(huishou);
        if(delhuishou==1){
            System.out.print("添加记录表");
            int addjilu = jiLuservice.addjilu(jilu);//添加一条记录
        }

        return delhuishou;

    }
}
